home *** CD-ROM | disk | FTP | other *** search
Wrap
Text File | 1992-07-13 | 34.6 KB | 1,198 lines | [ TEXT/PJMM]
{ * MemINIT cdev 2.0.3 * } { * * } { * The source code to the control panel part of MemINIT. * } { * Copyright © 1991-1992 Seth LaForge * } unit MemINITcdev; interface uses Types, GestaltEQU, SANE, Picker; function main (message, item, numItems, CPid: integer; event: EventRecord; cdevValue: Longint; dlg: DialogPtr): Longint; implementation const undoDev = 9; {For Undo menu commands} cutDev = 10; {For Cut menu commands} copyDev = 11; {For Copy menu commands} pasteDev = 12; {For Past menu commands} clearDev = 13; {For Clear menu commands} MemPICTBox = 1; ShowIcon = 2; BarActive = 3; BarLatency = 5; BarLatencyFrame = 6; BarLatencyArrows = 7; BarTickSpace = 10; BarTickSpaceFrame = 11; BarTickSpaceArrows = 12; BarColor = 15; BarDimBox = 16; BarSamplePICT = 17; BarSampleBox = 18; PieActive = 19; PieLatency = 21; PieLatencyFrame = 22; PieLatencyArrows = 23; PiePanColor = 26; PiePieColor = 28; PieDimBox = 29; PieSampleBox = 30; HelpButton = 31; MemINITRSRCVarsID = 0; MemINITColorPICTID = 256; MemINITBWPICTID = 257; AppleColorPICTID = 262; AppleBWPICTID = 263; sTrue = -1; sFalse = 0; type MIRSRCVars = record ShowIcon, VBLActive: signedByte; VBLTime: integer; UnitSize: longint; BarColor: RGBColor; PieActive: signedByte; PieTime: longint; PiePanColor: RGBColor; PiePieColor: RGBColor; end; MIRSRCVarsP = ^MIRSRCVars; MIRSRCVarsH = ^MIRSRCVarsP; MIMemVars = record rsrc: MIRSRCVars; VBLRec: VBLTask; VBLHeap: ptr; ColorAvail, Use32BitAddr, BlackColor: signedByte; MainPMap: PixMapPtr; ColorBits: longint; ColorSize, ColorIndex: integer; PieNextUpdate: longint; PiePort: CGrafPort; { Actually either grafPort or CGrafPort, depending on whether color QD exists. } OldDrawMBar, OldGNEFilter: procPtr; GestaltPresent, ScrnSaverPresent: signedByte; end; MIMemVarsP = ^MIMemVars; CDEVVars = record MemVars: MIMemVarsP; RSRCVars: MIRSRCVarsH; end; CDEVVarsP = ^CDEVVars; CDEVVarsH = ^CDEVVarsP; ArrowValueList = array[1..maxint] of OSType; ArrowValueListP = ^ArrowValueList; ArrowValueListH = ^ArrowValueListP; function ColorQDAvail: boolean; var theWorld: SysEnvRec; { System environment } theErr: OSErr; begin theErr := SysEnvirons(1, theWorld); { Check environment } ColorQDAvail := theWorld.hasColorQD; end; function TrapAvailable (trapNum: integer; tType: TrapType): Boolean; const _Unimplemented = $A89F; { Unimplemented trap } var theWorld: SysEnvRec; temp: OSErr; begin temp := SysEnvirons(1, theWorld); if (tType = ToolTrap) and ((theWorld.machineType < envMachUnknown) or ((theWorld.machineType > envMachUnknown) and (theWorld.machineType < envMacII))) then begin trapNum := BAND(trapNum, $3FF); { Traps numbers are 10 bits long } if trapNum > $1FF then begin { Traps only go up to 0x1FF on } TrapAvailable := FALSE; { these machines } Exit(TrapAvailable); end; end; { Compare the address of this trap with that of the } { unimplemented trap } TrapAvailable := NGetTrapAddress(trapNum, tType) <> GetTrapAddress(_Unimplemented); end; procedure WasteEvent; var theEvent: eventRecord; dummy: boolean; begin dummy := GetNextEvent(0, theEvent); end; const ArrowValuesType = 'ArVl'; function GetVal (FromStr: OSType): real; begin if FromStr = 'None' then GetVal := 0 else GetVal := Str2Num(FromStr); end; { SetArrowValuebyNum } { Sets the static text of an arrow control by comparing values with a real number and inserting the closest match. } procedure SetArrowValuebyNum (theDialog: DialogPtr; itemNumber: integer; theNumber: real; ValuesID: integer); var itemType: integer; itemHandle: handle; dispRect: rect; theArrowValues: ArrowValueListH; numValues, itemCtr: integer; ItemVal: real; begin theArrowValues := ArrowValueListH(GetResource(ArrowValuesType, ValuesID)); numValues := GetHandleSize(handle(theArrowValues)) div 4; for itemCtr := 1 to numValues do if GetVal(theArrowValues^^[itemCtr]) >= theNumber then Leave; if itemCtr > 1 then if theNumber < (GetVal(theArrowValues^^[itemCtr - 1]) + GetVal(theArrowValues^^[itemCtr])) / 2 then itemCtr := itemCtr - 1; { If the number is less than the average of a larger number and a smaller number, use the smaller. } GetDItem(theDialog, itemNumber, itemType, itemHandle, dispRect); SetIText(itemHandle, theArrowValues^^[itemCtr]); end; function FindArrowIndex (theDialog: DialogPtr; itemNumber: integer; ValuesID: integer): integer; var itemType: integer; itemHandle: handle; dispRect: rect; theArrowValues: ArrowValueListH; numValues, itemCtr: integer; itemText: str255; begin theArrowValues := ArrowValueListH(GetResource(ArrowValuesType, ValuesID)); numValues := GetHandleSize(handle(theArrowValues)) div 4; GetDItem(theDialog, itemNumber, itemType, itemHandle, dispRect); GetIText(itemHandle, itemText); for itemCtr := 1 to numValues do if theArrowValues^^[itemCtr] = itemText then begin FindArrowIndex := itemCtr; exit(FindArrowIndex); end; FindArrowIndex := 0; end; function ArrowHit (theDialog: DialogPtr; itemNumber, textItemNumber: integer; ValuesID: integer; var theEvent: EventRecord; procedure ChangeProc (theDialog: DialogPtr; itemNumber: integer)): boolean; { Returns true if item changed. } const StartSpeed = 20; Speed2 = 10; FlipsB4Increase = 3; NowhereIcon = 259; var curDir, nowDir: (nowhere, up, down); itemType: integer; itemHandle, TextHandle: handle; TextRect, ArrowRect, bigRect: rect; theArrowValues: ArrowValueListH; numValues, startIndex, curIndex: integer; curSpeed, nextChange: longint; SpeedCtr: integer; curPoint: point; curPICT: PicHandle; label 1; begin theArrowValues := ArrowValueListH(GetResource(ArrowValuesType, ValuesID)); numValues := GetHandleSize(handle(theArrowValues)) div 4; GetDItem(theDialog, itemNumber, itemType, itemHandle, ArrowRect); GetDItem(theDialog, textItemNumber, itemType, TextHandle, TextRect); startIndex := FindArrowIndex(theDialog, textItemNumber, ValuesID); curIndex := startIndex; curDir := nowhere; SetRect(bigRect, -32768, -32768, 32767, 32767); { For restoring full clip rgn. } curPoint := theEvent.where; GlobalToLocal(curPoint); repeat nowDir := nowhere; if PtInRect(curPoint, ArrowRect) then if curPoint.v <= (ArrowRect.top + ArrowRect.bottom) div 2 then nowDir := up else nowDir := down; if curDir <> nowDir then begin curPICT := GetPicture(NowhereIcon + ord(nowDir)); HNoPurge(handle(curPICT)); DrawPicture(curPICT, ArrowRect); HPurge(handle(curPICT)); curSpeed := StartSpeed; nextChange := 0; SpeedCtr := FlipsB4Increase; curDir := nowDir; end; if (curDir <> nowhere) and (TickCount >= nextChange) then { Time to actually do something! } begin if curDir = up then if curIndex >= numValues then goto 1 { There's no room to go up! } else curIndex := curIndex + 1 else { if curDir = down then } if curIndex <= 1 then goto 1 { There's no room to go down! } else curIndex := curIndex - 1; SpeedCtr := SpeedCtr - 1; if SpeedCtr = 0 then curSpeed := Speed2; nextChange := TickCount + curSpeed; SetIText(TextHandle, theArrowValues^^[curIndex]); ClipRect(TextRect); UpdtDialog(theDialog, theDialog^.clipRgn); ClipRect(BigRect); ChangeProc(theDialog, textItemNumber); end; 1: GetMouse(curPoint); until not stillDown; if curDir <> nowhere then begin curPICT := GetPicture(NowhereIcon); HNoPurge(handle(curPICT)); DrawPicture(curPICT, ArrowRect); HPurge(handle(curPICT)); end; ArrowHit := curIndex <> StartIndex; end; procedure CPenNormal; var theColor: RGBColor; begin if ColorQDAvail then begin with theColor do begin red := $FFFF; green := $FFFF; blue := $FFFF; end; RGBBackColor(theColor); with theColor do begin red := $0000; green := $0000; blue := $0000; end; RGBForeColor(theColor); end; end; procedure DrawPICTItem (theDialog: DialogPtr; itemNumber: integer); var thePICTID: integer; thePicture: PicHandle; itemType: integer; {For GetDItem} itemHandle: Handle; {For GetDItem} dispRect, globRect: Rect; {For GetDItem} theDevice: GDHandle; begin GetDItem(theDialog, itemNumber, itemType, itemHandle, dispRect); {Set some text} thePICTID := MemINITBWPICTID; if ColorQDAvail then begin globRect := dispRect; LocalToGlobal(globRect.topLeft); LocalToGlobal(globRect.botRight); theDevice := GetMaxDevice(globRect); if (theDevice <> nil) & (theDevice^^.gdPMap^^.PixelSize >= 4) then thePICTID := MemINITColorPICTID end; thePicture := GetPicture(thePICTID); HNoPurge(handle(thePicture)); dispRect.right := dispRect.left + (thePicture^^.picFrame.right - thePicture^^.picFrame.left); dispRect.bottom := dispRect.top + (thePicture^^.picFrame.bottom - thePicture^^.picFrame.top); DrawPicture(thePicture, dispRect); HPurge(handle(thePicture)); end; procedure DrawFrameItem (theDialog: DialogPtr; itemNumber: integer; MyVars: CDEVVarsH); var itemType: integer; {For GetDItem} itemHandle: Handle; {For GetDItem} dispRect: Rect; {For GetDItem} begin GetDItem(theDialog, itemNumber, itemType, itemHandle, dispRect); FrameRect(dispRect); end; procedure DrawGrayItem (theDialog: DialogPtr; itemNumber: integer; MyVars: CDEVVarsH); var itemType: integer; {For GetDItem} itemHandle: Handle; {For GetDItem} dispRect: Rect; {For GetDItem} grayPat: pattern; SavePen: PenState; begin GetPenState(SavePen); GetDItem(theDialog, itemNumber, itemType, itemHandle, dispRect); StuffHex(@grayPat, 'AA55AA55AA55AA55'); PenPat(grayPat); PenMode(patBIC); PaintRect(dispRect); SetPenState(SavePen); end; function ColorItemHit (theDialog: DialogPtr; itemNumber: integer; var theColor: RGBColor; Prompt: str255; var theEvent: EventRecord): boolean; var itemType: integer; {For GetDItem} itemHandle: Handle; {For GetDItem} dispRect: Rect; {For GetDItem} hilited: boolean; curMouse: point; begin ColorItemHit := false; GetDItem(theDialog, itemNumber, itemType, itemHandle, dispRect); insetRect(dispRect, 1, 1); PenSize(2, 2); PenMode(patXOR); hilited := false; curMouse := theEvent.where; GlobalToLocal(curMouse); repeat if PtInRect(curMouse, dispRect) <> hilited then begin FrameRect(dispRect); hilited := not hilited; end; GetMouse(curMouse); until not StillDown; if hilited then begin FrameRect(dispRect); setPt(curMouse, -1, -1); { Used for GetColor, signal to display on best screen. } if ColorQDAvail then ColorItemHit := GetColor(curMouse, Prompt, theColor, theColor) else SysBeep(5); end; PenSize(1, 1); end; procedure DrawColorItem (theDialog: DialogPtr; itemNumber: integer; theColor: RGBColor); var itemType: integer; {For GetDItem} itemHandle: Handle; {For GetDItem} dispRect, globRect: Rect; {For GetDItem} theDevice: GDHandle; begin GetDItem(theDialog, itemNumber, itemType, itemHandle, dispRect); FrameRect(dispRect); InsetRect(dispRect, 1, 1); EraseRect(dispRect); if ColorQDAvail then begin globRect := dispRect; LocalToGlobal(globRect.topLeft); LocalToGlobal(globRect.botRight); theDevice := GetMaxDevice(globRect); if (theDevice <> nil) & (theDevice^^.gdPMap^^.PixelSize >= 1) then RGBForeColor(theColor); end; InsetRect(dispRect, 2, 2); PaintRect(dispRect); CPenNormal; end; procedure DrawBarColorItem (theDialog: DialogPtr; itemNumber: integer; MyVars: CDEVVarsH); begin DrawColorItem(theDialog, itemNumber, myVars^^.RSRCVars^^.BarColor); end; procedure DrawPiePanColorItem (theDialog: DialogPtr; itemNumber: integer; MyVars: CDEVVarsH); begin DrawColorItem(theDialog, itemNumber, myVars^^.RSRCVars^^.PiePanColor); end; procedure DrawPiePieColorItem (theDialog: DialogPtr; itemNumber: integer; MyVars: CDEVVarsH); begin DrawColorItem(theDialog, itemNumber, myVars^^.RSRCVars^^.PiePieColor); end; procedure DrawBarSample (theDialog: DialogPtr; itemNumber: integer; MyVars: CDEVVarsH); var itemType: integer; {For GetDItem} itemHandle: Handle; {For GetDItem} dispRect, globRect: Rect; {For GetDItem} theDevice: GDHandle; begin if myVars^^.RSRCVars^^.VBLActive = sTrue then begin GetDItem(theDialog, itemNumber, itemType, itemHandle, dispRect); EraseRect(dispRect); if ColorQDAvail then begin globRect := dispRect; LocalToGlobal(globRect.topLeft); LocalToGlobal(globRect.botRight); theDevice := GetMaxDevice(globRect); if (theDevice <> nil) & (theDevice^^.gdPMap^^.PixelSize >= 1) then RGBForeColor(myVars^^.RSRCVars^^.BarColor); end; dispRect.right := dispRect.left + (dispRect.right - dispRect.left) div 3 * 2; PaintRect(dispRect); CPenNormal; end; end; procedure DrawPieSample (theDialog: DialogPtr; itemNumber: integer; MyVars: CDEVVarsH); var itemType: integer; {For GetDItem} itemHandle: Handle; {For GetDItem} dispRect, globRect: Rect; {For GetDItem} theDevice: GDHandle; SavePen: PenState; thePICTID: integer; thePicture: PicHandle; begin GetDItem(theDialog, itemNumber, itemType, itemHandle, dispRect); if myVars^^.RSRCVars^^.PieActive = sTrue then begin FrameOval(dispRect); GetPenState(SavePen); if ColorQDAvail then begin globRect := dispRect; LocalToGlobal(globRect.topLeft); LocalToGlobal(globRect.botRight); theDevice := GetMaxDevice(globRect); if (theDevice <> nil) & (theDevice^^.gdPMap^^.PixelSize >= 4) then begin RGBForeColor(myVars^^.RSRCVars^^.PiePieColor); RGBBackColor(myVars^^.RSRCVars^^.PiePanColor); end; end; insetRect(dispRect, 1, 1); EraseOval(dispRect); PaintArc(dispRect, 0, 240); CPenNormal; SetPenState(SavePen); end else begin EraseRect(dispRect); thePICTID := AppleBWPICTID; if ColorQDAvail then begin globRect := dispRect; LocalToGlobal(globRect.topLeft); LocalToGlobal(globRect.botRight); theDevice := GetMaxDevice(globRect); if (theDevice <> nil) & (theDevice^^.gdPMap^^.PixelSize >= 4) then thePICTID := AppleColorPICTID end; thePicture := GetPicture(thePICTID); HNoPurge(handle(thePicture)); with thePicture^^.picFrame do begin dispRect.left := (dispRect.left + dispRect.right - (right - left)) div 2; dispRect.top := (dispRect.top + dispRect.bottom - (bottom - top)) div 2; dispRect.right := dispRect.left + (right - left); dispRect.bottom := dispRect.top + (bottom - top); end; DrawPicture(thePicture, dispRect); HPurge(handle(thePicture)); end; end; function ItemVisible (theDialog: DialogPtr; theItem: integer): boolean; var itemType: integer; itemHandle: handle; dispRect: rect; begin GetDItem(theDialog, theItem, itemType, itemHandle, dispRect); ItemVisible := SectRect(dispRect, theDialog^.PortRect, dispRect); end; function GetScreenRect: rect; var WManagerPort: GrafPtr; begin GetWMgrPort(WManagerPort); GetScreenRect := WManagerPort^.portRect; end; function Min (N1, N2: longint): longint; begin if N1 <= N2 then Min := N1 else Min := N2; end; function Max (N1, N2: longint): longint; begin if N1 >= N2 then Max := N1 else Max := N2; end; const {• OK = 1;•} OKFrame = 2; MemINITPict = 3; TextBox = 4; TextScrollBar = 5; procedure DrawOKFrame (theDialog: DialogPtr; theItem: integer); var itemType: integer; itemHandle: Handle; dispRect: Rect; begin GetDItem(theDialog, theItem, itemType, itemHandle, dispRect); PenSize(3, 3); FrameRoundRect(dispRect, 16, 16); PenSize(1, 1); end; procedure DrawTextBox (theDialog: DialogPtr; theItem: integer); var itemType: integer; itemHandle: Handle; dispRect: Rect; begin GetDItem(theDialog, theItem, itemType, itemHandle, dispRect); FrameRect(dispRect); TEUpdate(dispRect, TEHandle(WindowPeek(theDialog)^.refCon)); end; procedure HelpScrollControlAction (theControl: ControlHandle; thePart: integer); var theDialog: WindowPeek; OldCtlValue, NewCtlValue: integer; TextTE: TEHandle; begin GetPort(GrafPtr(theDialog)); TextTE := TEHandle(theDialog^.RefCon); OldCtlValue := theControl^^.ContrlRfCon; NewCtlValue := GetCtlValue(theControl); if thePart = InUpButton then NewCtlValue := max(GetCtlMin(theControl), NewCtlValue - 1) else if thePart = InDownButton then NewCtlValue := min(GetCtlMax(theControl), NewCtlValue + 1) else if thePart = InPageUp then NewCtlValue := max(GetCtlMin(theControl), NewCtlValue - ((TextTE^^.viewRect.bottom - TextTE^^.viewRect.top) div TextTE^^.lineHeight - 1)) else if thePart = InPageDown then NewCtlValue := min(GetCtlMax(theControl), NewCtlValue + ((TextTE^^.viewRect.bottom - TextTE^^.viewRect.top) div TextTE^^.lineHeight - 1)); if NewCtlValue <> GetCtlValue(theControl) then SetCtlValue(theControl, NewCtlValue); TEScroll(0, (OldCtlValue - NewCtlValue) * TextTE^^.lineHeight, TextTE); theControl^^.ContrlRfCon := GetCtlValue(theControl); end; function HelpFilter (theDialog: DialogPtr; var theEvent: EventRecord; var itemNumber: integer): boolean; const crCode = 13; enterCode = 3; var itemType: integer; itemHandle: Handle; dispRect: Rect; PartHit: integer; HitPt: point; ignoreLong: longint; begin HelpFilter := false; if theEvent.what = MouseDown then begin SetPort(theDialog); HitPt := theEvent.where; GlobalToLocal(HitPt); GetDItem(theDialog, TextScrollBar, itemType, itemHandle, dispRect); if ptInRect(HitPt, dispRect) then begin HelpFilter := true; ControlHandle(itemHandle)^^.ContrlRfCon := GetCtlValue(ControlHandle(itemHandle)); PartHit := TestControl(ControlHandle(itemHandle), HitPt); if PartHit <> 0 then if PartHit <> InThumb then PartHit := TrackControl(ControlHandle(itemHandle), HitPt, @HelpScrollControlAction) else begin PartHit := TrackControl(ControlHandle(itemHandle), HitPt, nil); HelpScrollControlAction(ControlHandle(itemHandle), PartHit); end; end; end else if theEvent.what = keyDown then if (theEvent.message mod 256) in [crCode, enterCode] then begin {user pressed Return or Enter} GetDItem(theDialog, OK, itemType, itemHandle, dispRect); HiliteControl(ControlHandle(itemHandle), 1); {make it look...} Delay(5, ignoreLong); {...like the OK button was hit} HiliteControl(ControlHandle(itemHandle), 0); HelpFilter := TRUE; {dialog is over} itemNumber := OK; {have ModalDialog return that the user hit OK} end; end; {This procedure puts up an about box and brags about us.} procedure DoHelp; const HelpDLOGID = 256; HelpTEXTID = 256; var OldPort: GrafPtr; theDialog: DialogPtr; DialogPt: point; Done: boolean; itemType: integer; itemHandle: Handle; dispRect: Rect; TextTE: TEHandle; theHelpText: handle; NewCtlMax: integer; itemhit: integer; begin GetPort(OldPort); theDialog := GetNewDialog(HelpDLOGID, nil, WindowPtr(-1)); {Get our dialog from the resource} dispRect := GetScreenRect; DialogPt.h := (dispRect.right - (theDialog^.portRect.right - theDialog^.portRect.left)) div 2; DialogPt.v := (dispRect.bottom - (theDialog^.portRect.bottom - theDialog^.portRect.top)) div 2; MoveWindow(theDialog, DialogPt.h, DialogPt.v, True); {Center our dialog. } SetPort(theDialog); {Set the port to our dialog} TextFont(geneva); {Set the font} TextSize(9); {Set the font size} GetDItem(theDialog, MemINITPict, itemType, itemHandle, dispRect); SetDItem(theDialog, MemINITPict, itemType, @DrawPICTItem, dispRect); GetDItem(theDialog, OKFrame, itemType, itemHandle, dispRect); SetDItem(theDialog, OKFrame, itemType, @DrawOKFrame, dispRect); GetDItem(theDialog, TextBox, itemType, itemHandle, dispRect); SetDItem(theDialog, TextBox, itemType, @DrawTextBox, dispRect); InsetRect(dispRect, 6, 4); TextTE := TENew(dispRect, dispRect); theHelpText := GetResource('TEXT', HelpTEXTID); if theHelpText <> nil then begin HLock(theHelpText); TESetText(theHelpText^, GetHandleSize(theHelpText), TextTE); { Makes a copy of the text. } HUnLock(theHelpText); ReleaseResource(theHelpText); NewCtlMax := TextTE^^.nLines - ((TextTE^^.viewRect.bottom - TextTE^^.viewRect.top) div TextTE^^.lineHeight); GetDItem(theDialog, TextScrollBar, itemType, itemHandle, dispRect); if NewCtlMax >= 0 then SetCtlMax(ControlHandle(itemHandle), NewCtlMax); end; WindowPeek(theDialog)^.RefCon := longint(TextTE); ShowWindow(theDialog); Done := false; repeat Modaldialog(@HelpFilter, itemhit); case itemhit of OK: Done := true; end; until done; TEDispose(TextTE); DisposDialog(theDialog); {Take down our dialog} SetPort(OldPort); end; procedure UpdateGrays (theDialog: DialogPtr; numItems: integer; MyVars: CDEVVarsH); var itemType: integer; itemHandle: handle; dispRect: rect; NewActivate: boolean; begin { Do bar section. } NewActivate := MyVars^^.RSRCVars^^.VBLActive <> sFalse; if NewActivate <> (not ItemVisible(theDialog, numItems + BarDimBox)) then if NewActivate then HideDItem(theDialog, numItems + BarDimBox) { Will invalidate for us. } else begin ShowDItem(theDialog, numItems + BarDimBox); DrawGrayItem(theDialog, numItems + BarDimBox, MyVars); GetDItem(theDialog, numItems + BarDimBox, itemType, itemHandle, dispRect); ValidRect(dispRect); end; { Do pie section. } NewActivate := myVars^^.RSRCVars^^.PieActive <> sFalse; if NewActivate <> not ItemVisible(theDialog, numItems + PieDimBox) then if NewActivate then HideDItem(theDialog, numItems + PieDimBox) { Will invalidate for us. } else begin ShowDItem(theDialog, numItems + PieDimBox); DrawGrayItem(theDialog, numItems + PieDimBox, MyVars); GetDItem(theDialog, numItems + PieDimBox, itemType, itemHandle, dispRect); ValidRect(dispRect); end; end; function InitItems (theDialog: DialogPtr; numItems: integer): CDEVVarsH; const OurSelector = 'MemV'; var itemType: integer; {For GetDItem} itemHandle: Handle; {For GetDItem} dispRect: Rect; {For GetDItem} myErr: OSErr; MyVars: CDEVVarsH; MemVars: MIMemVarsP; RSRCVars: MIRSRCVarsH; aStr: str255; begin MyVars := CDEVVarsH(NewHandle(sizeof(CDEVVars))); if MyVars = nil then begin InitItems := nil; { We won't continue... } exit(InitItems); end; InitItems := MyVars; myErr := Gestalt(OurSelector, longint(MemVars)); { The glue will catch us if Gestalt isn't implemented. } if myErr <> noErr then MemVars := nil; MyVars^^.MemVars := MemVars; RSRCVars := MIRSRCVarsH(GetResource('MVar', MemINITRSRCVarsID)); MyVars^^.RSRCVars := RSRCVars; GetDItem(theDialog, numItems + ShowIcon, itemType, itemHandle, dispRect); if RSRCVars^^.ShowIcon = sFalse then SetCtlValue(ControlHandle(itemHandle), 0) else SetCtlValue(ControlHandle(itemHandle), 1); GetDItem(theDialog, numItems + BarActive, itemType, itemHandle, dispRect); if RSRCVars^^.VBLActive = sFalse then SetCtlValue(ControlHandle(itemHandle), 0) else SetCtlValue(ControlHandle(itemHandle), 1); SetArrowValuebyNum(theDialog, numItems + BarLatency, RSRCVars^^.VBLTime / 60, BarLatencyArrows); SetArrowValuebyNum(theDialog, numItems + BarTickSpace, RSRCVars^^.UnitSize / 1024, BarTickSpaceArrows); GetDItem(theDialog, numItems + PieActive, itemType, itemHandle, dispRect); if RSRCVars^^.PieActive = sFalse then SetCtlValue(ControlHandle(itemHandle), 0) else SetCtlValue(ControlHandle(itemHandle), 1); SetArrowValuebyNum(theDialog, numItems + PieLatency, RSRCVars^^.PieTime / 60, PieLatencyArrows); HideDItem(theDialog, numItems + BarDimBox); { Force UpdateGrays to deactivate text... } HideDItem(theDialog, numItems + PieDimBox); UpdateGrays(theDialog, numItems, MyVars); GetDItem(theDialog, numItems + BarDimBox, itemType, itemHandle, dispRect); InvalRect(dispRect); GetDItem(theDialog, numItems + PieDimBox, itemType, itemHandle, dispRect); InvalRect(dispRect); end; {This is where we process a hit on one of our controls in the cdev.} procedure Hit (theDialog: DialogPtr; numItems: integer; MyVars: CDEVVarsH; item: integer; var theEvent: EventRecord); { item has already been offset for us. } var itemType: integer; itemHandle: handle; dispRect: rect; procedure ArrowStateChange (theDialog: DialogPtr; itemNumber: integer); var theText: str255; aReal: real; begin GetDItem(theDialog, itemNumber, itemType, itemHandle, dispRect); GetIText(itemHandle, theText); aReal := GetVal(theText); case item of BarLatencyArrows: begin if MyVars^^.MemVars <> nil then begin MyVars^^.MemVars^.rsrc.VBLTime := round(aReal * 60); MyVars^^.MemVars^.VBLRec.VBLCount := 1; { Update immediately. } end; MyVars^^.RSRCVars^^.VBLTime := round(aReal * 60); end; BarTickSpaceArrows: begin if MyVars^^.MemVars <> nil then begin MyVars^^.MemVars^.rsrc.UnitSize := round(aReal * 1024); MyVars^^.MemVars^.VBLRec.VBLCount := 1; { Update immediately. } end; MyVars^^.RSRCVars^^.UnitSize := round(aReal * 1024); end; PieLatencyArrows: begin if MyVars^^.MemVars <> nil then begin MyVars^^.MemVars^.rsrc.PieTime := round(aReal * 60); MyVars^^.MemVars^.PieNextUpdate := 0; { Update immediately. } end; MyVars^^.RSRCVars^^.PieTime := round(aReal * 60); end; end; ChangedResource(handle(MyVars^^.RSRCVars)); end; begin GetDItem(theDialog, numItems + item, itemType, itemHandle, dispRect); case item of BarLatencyArrows, BarTickSpaceArrows, PieLatencyArrows: if ArrowHit(theDialog, numItems + item, numItems + item - 2, item, theEvent, ArrowStateChange) then WriteResource(handle(MyVars^^.RSRCVars)); BarColor: if ColorItemHit(theDialog, numItems + item, MyVars^^.RSRCVars^^.BarColor, 'Bar color:', theEvent) then begin if MyVars^^.MemVars <> nil then begin MyVars^^.MemVars^.rsrc.BarColor := MyVars^^.RSRCVars^^.BarColor; MyVars^^.MemVars^.ColorSize := 0; { Force color update. } WasteEvent; { Have our jGNEFilter called, so we'll be updated. } MyVars^^.MemVars^.VBLRec.VBLCount := 1; { Update immediately. } end; ChangedResource(handle(MyVars^^.RSRCVars)); WriteResource(handle(MyVars^^.RSRCVars)); end; ShowIcon: begin SetCtlValue(ControlHandle(itemHandle), 1 - GetCtlValue(ControlHandle(itemHandle))); if GetCtlValue(ControlHandle(itemHandle)) = 1 then MyVars^^.RSRCVars^^.ShowIcon := sTrue else MyVars^^.RSRCVars^^.ShowIcon := sFalse; ChangedResource(handle(MyVars^^.RSRCVars)); WriteResource(handle(MyVars^^.RSRCVars)); end; BarActive: begin SetCtlValue(ControlHandle(itemHandle), 1 - GetCtlValue(ControlHandle(itemHandle))); if GetCtlValue(ControlHandle(itemHandle)) = 1 then MyVars^^.RSRCVars^^.VBLActive := sTrue else MyVars^^.RSRCVars^^.VBLActive := sFalse; if MyVars^^.MemVars <> nil then begin MyVars^^.MemVars^.rsrc.VBLActive := MyVars^^.RSRCVars^^.VBLActive; if MyVars^^.MemVars^.rsrc.VBLActive = sFalse then DrawMenuBar { Erase old bar. } else begin MyVars^^.MemVars^.ColorSize := 0; { Force color update. } WasteEvent; { Have our jGNEFilter called, so we'll be updated. } MyVars^^.MemVars^.VBLRec.VBLCount := 1; { Update immediately. } end; end; ChangedResource(handle(MyVars^^.RSRCVars)); WriteResource(handle(MyVars^^.RSRCVars)); GetDItem(theDialog, numItems + BarSamplePICT, itemType, itemHandle, dispRect); InvalRect(dispRect); UpdateGrays(theDialog, numItems, MyVars); end; PieActive: begin SetCtlValue(ControlHandle(itemHandle), 1 - GetCtlValue(ControlHandle(itemHandle))); if GetCtlValue(ControlHandle(itemHandle)) = 1 then MyVars^^.RSRCVars^^.PieActive := sTrue else MyVars^^.RSRCVars^^.PieActive := sFalse; if MyVars^^.MemVars <> nil then begin MyVars^^.MemVars^.rsrc.PieActive := MyVars^^.RSRCVars^^.PieActive; if MyVars^^.MemVars^.rsrc.PieActive = sFalse then DrawMenuBar { Erase old bar. } else begin MyVars^^.MemVars^.PieNextUpdate := 0; { Update immediately. } WasteEvent; { Have our jGNEFilter called, so we'll be updated. } end; end; ChangedResource(handle(MyVars^^.RSRCVars)); WriteResource(handle(MyVars^^.RSRCVars)); GetDItem(theDialog, numItems + PieSampleBox, itemType, itemHandle, dispRect); InvalRect(dispRect); UpdateGrays(theDialog, numItems, MyVars); end; PiePieColor: if ColorItemHit(theDialog, numItems + item, MyVars^^.RSRCVars^^.PiePieColor, 'Pie color:', theEvent) then begin if MyVars^^.MemVars <> nil then begin MyVars^^.MemVars^.rsrc.PiePieColor := MyVars^^.RSRCVars^^.PiePieColor; MyVars^^.MemVars^.PieNextUpdate := 0; { Update immediately. } WasteEvent; { Have our jGNEFilter called, so we'll be updated. } end; ChangedResource(handle(MyVars^^.RSRCVars)); WriteResource(handle(MyVars^^.RSRCVars)); end; PiePanColor: if ColorItemHit(theDialog, numItems + item, MyVars^^.RSRCVars^^.PiePanColor, 'Pie pan color:', theEvent) then begin if MyVars^^.MemVars <> nil then begin MyVars^^.MemVars^.rsrc.PiePanColor := MyVars^^.RSRCVars^^.PiePanColor; MyVars^^.MemVars^.PieNextUpdate := 0; { Update immediately. } WasteEvent; { Have our jGNEFilter called, so we'll be updated. } end; ChangedResource(handle(MyVars^^.RSRCVars)); WriteResource(handle(MyVars^^.RSRCVars)); end; HelpButton: DoHelp; end; end; procedure Close (theDialog: DialogPtr; numItems: integer; var MyVars: CDEVVarsH); begin if Longint(MyVars) > cdevUnset then { It has to be bigger than this to be a handle. } DisposHandle(handle(MyVars)); MyVars := CDEVVarsH(cdevUnset); end; {Update - handles update events in the cdev. Much like you would do in a normal application} {except that you don't need to call "BeginUpdate" and "EndUpdate".} procedure Update (theDialog: DialogPtr; numItems: integer; MyVars: CDEVVarsH); begin DrawPICTItem(theDialog, numItems + MemPICTBox); DrawFrameItem(theDialog, numItems + BarLatencyFrame, MyVars); DrawFrameItem(theDialog, numItems + BarTickSpaceFrame, MyVars); DrawFrameItem(theDialog, numItems + PieLatencyFrame, MyVars); DrawBarColorItem(theDialog, numItems + BarColor, MyVars); DrawPiePanColorItem(theDialog, numItems + PiePanColor, MyVars); DrawPiePieColorItem(theDialog, numItems + PiePieColor, MyVars); DrawGrayItem(theDialog, numItems + BarDimBox, MyVars); DrawGrayItem(theDialog, numItems + PieDimBox, MyVars); DrawBarSample(theDialog, numItems + BarSampleBox, MyVars); DrawPieSample(theDialog, numItems + PieSampleBox, MyVars); end; {Take action when Control Panel is activated.} procedure Activate (theDialog: DialogPtr; numItems: integer; MyVars: CDEVVarsH); begin end; {Take action when Control Panel is Deactivated.} procedure Deactivate (theDialog: DialogPtr; numItems: integer; MyVars: CDEVVarsH); begin end; {Some time from the system. Use it if you need it. An example use would be calling} {TEIdle.} procedure Idle (theDialog: DialogPtr; numItems: integer; MyVars: CDEVVarsH); begin end; {Key - handles key events when the cdev is active. This is where you must have your} {command keys (if any) handled as well.} procedure Key (theDialog: DialogPtr; numItems: integer; MyVars: CDEVVarsH; event: EventRecord); var ch: char; {To get the character pressed} begin if event.what <> autoKey then {If its not an autoKey event} begin if BitAnd(event.modifiers, CmdKey) <> 0 then {Is the Command Key down?} ch := chr(BitAnd(event.message, charCodeMask)); {Convert to char} case ch of {Case it} 'z', 'Z': {These are the standard Edit Cmd Keys} SysBeep(1); {Add yours in below} 'x', 'X': SysBeep(1); 'c', 'C': SysBeep(1); 'v', 'V': SysBeep(1); end; end; end; {This is our main routine} function main (message, item, numItems, CPid: integer; event: EventRecord; cdevValue: Longint; dlg: DialogPtr): Longint; begin if cdevValue > cdevUnset then { It has to be bigger than this to be a handle. } begin HLock(handle(cdevValue)); HLock(handle(CDEVVarsH(cdevValue)^^.RSRCVars)); end; case message of initDev: cdevValue := longint(InitItems(dlg, numItems)); hitDev: Hit(dlg, numItems, CDEVVarsH(cdevValue), item - numItems, event); closeDev: Close(dlg, numItems, CDEVVarsH(cdevValue)); nulDev: Idle(dlg, numItems, CDEVVarsH(cdevValue)); updateDev: Update(dlg, numItems, CDEVVarsH(cdevValue)); activDev: Activate(dlg, numItems, CDEVVarsH(cdevValue)); deactivDev: Deactivate(dlg, numItems, CDEVVarsH(cdevValue)); keyEvtDev: Key(dlg, numItems, CDEVVarsH(cdevValue), event); undoDev: sysBeep(1); cutDev: sysBeep(1); copyDev: sysBeep(1); pasteDev: sysBeep(1); clearDev: sysBeep(1); end; if cdevValue > cdevUnset then { It has to be bigger than this to be a handle. } begin HUnLock(handle(cdevValue)); HLock(handle(CDEVVarsH(cdevValue)^^.RSRCVars)); end; main := cdevValue; end; end.